﻿Imports Microsoft.VisualBasic
Imports System.Data
Imports System.ComponentModel
Public Class Programas
    Inherits BDDatos
    Sub New()
        Me.Tabla = "Programas"
        Me.Vista = "VProgramas"
    End Sub
    Public COD_PROGRAMA As String
    Public COD_FACULTAD As String
    Public NOM_PROGRAMA As String
    Public CODIGO_PK1 As String
    Public CODIGO_PK2 As String
    Public RESOLUCION As String
    Public SENA As String
    Public NOMBRE_SENA As String
    Public Function Insert() As String
        Dim msg As String
        Me.Conectar()
        Try
            Dim querystring As String = "Insert into Programas(Cod_Facultad,Cod_Programa,Nom_Programa,Resolucion,Sena,Nombre_Sena)values(:Cod_Facultad,:Cod_Programa,:Nom_Programa,:Resolucion,:Sena,:Nombre_Sena)"
            Me.CrearComando(querystring)
            Me.AsignarParametroCadena(":Cod_Facultad", UCase(COD_FACULTAD))
            Me.AsignarParametroCadena(":Nom_Programa", UCase(NOM_PROGRAMA))
            Me.AsignarParametroCadena(":Cod_Programa", UCase(COD_PROGRAMA))
            Me.AsignarParametroCadena(":Resolucion", UCase(RESOLUCION))
            Me.AsignarParametroCadena(":Sena", UCase(SENA))
            Me.AsignarParametroCadena(":Nombre_Sena", UCase(NOMBRE_SENA))
            Dim numfilas As String = EjecutarComando()
            msg = "Se realizó la insercion exitosamente-" & numfilas
        Catch ex As Exception
            msg = "Error: " & ex.Message
        Finally
            Me.Desconectar()
        End Try
        Return msg
    End Function
    Public Function Delete() As String
        Dim msg As String
        Me.Conectar()
        Try
            Me.querystring = "Delete From Programas Where ID =:Codigo_PK1"
            Me.CrearComando(querystring)
            Me.AsignarParametroCadena(":Codigo_PK1", CODIGO_PK1)
            'Throw New Exception(querystring)
            Dim numfilas As String = EjecutarComando()
            msg = "Se Eliminó el registro exitosamente-" & numfilas
        Catch ex As Exception
            msg = "Error: " & ex.Message
        Finally
            Me.Desconectar()
        End Try
        Return msg
    End Function
    Public Function Update() As String
        Dim msg As String
        Me.Conectar()
        Try
            Me.querystring = "Update Programas set Cod_Facultad=:Cod_Facultad, Nom_Programa=:Nom_Programa, Cod_Programa=:Cod_Programa, Resolucion=:Resolucion, Sena=:Sena, Nombre_Sena=:Nombre_Sena Where ID=:ID"
            Me.CrearComando(querystring)
            Me.AsignarParametroCadena(":Cod_Facultad", UCase(COD_FACULTAD))
            Me.AsignarParametroCadena(":Nom_Programa", UCase(NOM_PROGRAMA))
            Me.AsignarParametroCadena(":Cod_Programa", UCase(COD_PROGRAMA))
            Me.AsignarParametroCadena(":Resolucion", UCase(RESOLUCION))
            Me.AsignarParametroCadena(":Sena", UCase(SENA))
            Me.AsignarParametroCadena(":Nombre_Sena", UCase(NOMBRE_SENA))
            Me.AsignarParametroCadena(":ID", CODIGO_PK1)
            'Throw New Exception(querystring)
            Dim numfilas As String = EjecutarComando()
            msg = "Se Actualizó el registro exitosamente- [" & numfilas & "] Filas Afectadas"
        Catch ex As Exception
            msg = "Error: " & ex.Message
        Finally
            Me.Desconectar()
        End Try
        Return msg
    End Function
    <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
    Public Function consultar(ByVal busc As String) As DataTable
        Me.Conectar()
        If Not String.IsNullOrEmpty(busc) Then
            Me.querystring = "select * from VProgramas where upper(cod_programa) like :Buscar or upper(nom_programa) like :Buscar order by cod_facultad, Nom_Programa"
            CrearComando(querystring)
            Me.AsignarParametroCadena(":Buscar", "%" & UCase(busc) & "%")
            Me.AsignarParametroCadena(":Buscar", "%" & UCase(busc) & "%")
        Else
            Me.querystring = "select * from VProgramas order by cod_facultad, Nom_Programa"
            CrearComando(querystring)
        End If
        Dim dt As DataTable = EjecutarConsultaDataTable()
        Me.Desconectar()
        Return dt
    End Function
    <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
    Public Function consultarxFacultad(ByVal Cod_Fac As String) As DataTable
        Me.Conectar()
        Me.querystring = "select * from Programas where upper(cod_facultad)=:Buscar"
        CrearComando(querystring)
        Me.AsignarParametroCadena(":Buscar", UCase(Cod_Fac))
        Dim dt As DataTable = EjecutarConsultaDataTable()
        Me.Desconectar()
        Return dt
    End Function
    Public Function consultarPorCod(ByVal Cod_Fac As String, ByVal Cod_Prog As String) As DataTable
        Me.Conectar()
        Me.querystring = "select * from vprogramas where Cod_facultad = '" & Cod_Fac & "' and Cod_Programa='" & Cod_Prog & "'"
        CrearComando(querystring)
        Dim dt As DataTable = EjecutarConsultaDataTable()
        Me.Desconectar()
        Return dt
    End Function


    Public Shared Function consultarPorParametro(ByVal cedula As String) As DataTable
        'declarmos variable local'
        Dim dt As New DataTable
        Dim sentencia As String
        sentencia = "select * from Afiliados where CEDULA = :CEDULA"
        dt = Datos.RegresarDatos(sentencia)
        Return dt
    End Function
End Class
